home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / comm / net / AMarquee1_48.lha / AMarquee / examples / streamgen.c < prev    next >
C/C++ Source or Header  |  1998-04-10  |  3KB  |  98 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #include <dos/dos.h>
  7. #include <clib/dos_protos.h>
  8. #include <clib/exec_protos.h>
  9.  
  10. #include <clib/AMarquee_protos.h>
  11.  
  12. #include <pragmas/AMarquee_pragmas.h>
  13.  
  14. #define UNLESS(x) if (!(x))
  15.  
  16. struct Library * AMarqueeBase = NULL;
  17. struct QSession * session     = NULL;
  18.  
  19. void CleanExit(void)
  20. {
  21.   if (session)      QFreeSession(session);       /* This MUST be done before we close the library! */
  22.   if (AMarqueeBase) CloseLibrary(AMarqueeBase);
  23.   printf("All done.\n");
  24. }
  25.  
  26. /* Main program--simply increments our counter using a stream. */
  27. int main(int argc, char ** argv)
  28. {
  29.   char * connectTo, * progName;
  30.   int port = 2957;
  31.   int count = 0;
  32.   
  33.   atexit(CleanExit);
  34.     
  35.   printf("StreamGen: This program continually updates an integer on the server.\n");
  36.   printf("           It uses QStreamOp(), so anyone subscribing to streamcount\n");
  37.   printf("           should see a monotonously increasing stream of integers.\n\n");
  38.   printf("Usage Note :  StreamGen [host=hostname] [name=streamgen]\n");
  39.  
  40.   connectTo = (argc > 1) ? argv[1] : "localhost";
  41.   progName  = (argc > 2) ? argv[2] : "streamgen";
  42.  
  43.   if ((AMarqueeBase = OpenLibrary("amarquee.library",37L)) == NULL)
  44.   {
  45.     printf("Couldn't open amarquee.library v37!\n");
  46.     exit(RETURN_ERROR);
  47.   }
  48.   printf("Connecting to %s:%i...\n",connectTo, port);
  49.   if ((session = QNewSession(connectTo, port, progName)) == NULL)
  50.   {
  51.     printf("Couldn't connect to server %s:%i\n",connectTo, port);
  52.     CloseLibrary(AMarqueeBase);
  53.     exit(RETURN_WARN);
  54.   }
  55.   printf("StreamGen connected to server %s:%i\n",connectTo, port);
  56.  
  57.   /* Setup */
  58.   while(1)
  59.   {
  60.     struct QMessage * msg;
  61.     char data[1000];
  62.     
  63. /*    printf("Streaming %i...\r",count); fflush(stdout); */
  64. /*    UNLESS(QStreamOp(session, "streamcount", &count, sizeof(count))) */
  65.     UNLESS(QStreamOp(session, "streamcount", data, sizeof(data)))
  66.     {
  67.       printf("QStreamOp() (even) failed, aborting!\n");
  68.       break;    
  69.     } 
  70.     count++;
  71.     UNLESS(QGo(session, 0L))
  72.     {
  73.       printf("QGo() failed, aborting!\n");
  74.       break;
  75.     }
  76.     
  77.     if ((count % 100) == 0) 
  78.     {
  79.       Delay(100);
  80.       printf("Next burst (%i)...\n",count);
  81.     }
  82.         
  83.     /* Check for any error messages */
  84.     while(msg = (struct QMessage *)GetMsg(session->qMsgPort))
  85.     {
  86.       int stat = msg->qm_Status;
  87.       
  88.       FreeQMessage(session, msg);
  89.       if (stat != QERROR_NO_ERROR)
  90.       {
  91.         printf("Received an error message, closing the connection\n");
  92.         exit(RETURN_ERROR);
  93.       }
  94.     }
  95.   }
  96.   /* CleanExit called here via the atexit() feature */
  97. }
  98.